﻿using System;

namespace XDCCManager.Model.Packs
{
	public class EditedPack : BaseModel, IPack, INavigable
	{
		#region IPack Members

		private string description;

		public string Description
		{
			get { return description; }
			set { if (description != value) { description = value; OnPropertyChanged("Description"); } }
		}

		public int Gets
		{
			get
			{
				return (Source != null) ? Source.Gets : -1;
			}
			set
			{
				throw new NotSupportedException();
			}
		}

		private string note;

		public string Note
		{
			get { return note; }
			set { if (note != value) { note = value; OnPropertyChanged("Note"); } }
		}

		public int Number
		{
			get
			{
				return (Source != null) ? Source.Number : 0;
			}
			set
			{
				throw new NotSupportedException();
			}
		}

		public int Size
		{
			get
			{
				return (Source != null) ? Source.Size : -1;
			}
			set
			{
				throw new NotSupportedException();
			}
		}

		#endregion

		#region INavigable Members

		public INavigable Before { get; set; }

		public INavigable After { get; set; }

		private IPack source;

		public IPack Source
		{
			get { return source; }
			set
			{
				if (source != value)
				{
					if (source != null)
						(source as System.ComponentModel.INotifyPropertyChanged).PropertyChanged -= Source_PropertyChanged;
					source = value;
					if (source != null)
						(source as System.ComponentModel.INotifyPropertyChanged).PropertyChanged += Source_PropertyChanged;
				}
			}
		}

		void Source_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
		{
			if ((e.PropertyName == "Gets") || (e.PropertyName == "Size"))
				OnPropertyChanged(e.PropertyName);
		}

		public IPack Destination { get; set; }

		#endregion
	}
}
